<template>
  <div class="home w80 mg0auto">
    <QuestionLibBox
      v-for="(item, index) in state.libList"
      :key="index"
      :msg="item"
      :class="['w45', 'float-left', index % 2 === 0 ? 'mgr5' : '']"
      @route-lib="fnToApp"
    />
    <div class="clean-float"></div>
  </div>
</template>

<script>
import { defineProps, reactive } from "vue";
import QuestionLibBox from "../components/Box/QuestionLibBox/QuestionLibBox.vue";
import { post_ } from "../http/api.js";

export default {
  // 子组件
  components: {
    QuestionLibBox,
  },
  // 父组件传值
  props: {
    msg: String,
  },
  // 父组件时间
  emits: ["frompage-info"],
  // 钩子
  setup(props, { emit }) {
    // 双向绑定数据
    const state = reactive({
      libList: [],
    });
    // 回传父组件
    const fnToApp = (val) => {
      emit("frompage-info", val);
    };
    // 写入模板
    return { state, fnToApp };
  },
  // 钩子
  created() {
    // 查询题库
    post_("api/pub/getLib", {
      id: 0,
      title: "",
      describe: "",
    }).then((res) => {
      this.state.libList = res;
    });
  },
};
</script>
